// element 组件，一些常用的代码块
const obj = {
  methods: {
    __messageBox({ title, msg = '提示', msgType = 'warning',
        successMsg = '成功', infoMsg = '已取消',
        successCallback,
        cancelCallback }) {
      this.$confirm(title, msg, {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: msgType
      }).then(async () => {
        if (successCallback) {
          const code = await successCallback()
          if (code === 0) {
            this.$message({
              type: 'success',
              message: successMsg
            })
          }
          return
        }
        this.$message({
          type: 'success',
          message: successMsg
        })
      }).catch((e) => {
        console.log(e)
        cancelCallback && cancelCallback()
        this.$message({
          type: 'info',
          message: infoMsg
        })
      })
    },
    __notify(title = '成功', message = '操作成功', type = 'success') {
      title = title || '成功'
      message = message || '操作成功'
      this.$notify({
        title,
        message,
        type
      })
    },

    __checkUploadFile(file, size = 2) {
      const isLt2M = file.size / 1024 / 1024 < size
      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 2MB!')
      }
      return isLt2M
    }
  }
}

export default obj
